/*
   This class can be inheritted from to create forms as widgets.
   
   Please remember to add any widgets you want validated to this.mChildWidgets.
   The class expects a JSON responce for an error AND an error code to be set in the HTTP responce header.  Besed used with NoBuisnessBase/Utility/Status on the Zend side.
*/
define(
   [
      'dojo/_base/declare',
      'dojo/_base/lang',
      'dojo/Evented',
      'dijit/_WidgetBase',
      'dijit/_TemplatedMixin'
   ],
   function(declare, lang, Evented, _WidgetBase, _TemplatedMixin)
   {
      return declare([_WidgetBase, _TemplatedMixin, Evented],
      {
         widgetsInTemplate: true,
         postscript: function(args)
         {
            this.mChildWidgets = [];
            this.inherited(arguments);
         },
         getChildren: function()
         {
            var children = this.inherited(arguments);
            if(this.mChildWidgets)
               children = children.concat(this.mChildWidgets);

            return children;
         },
         preSubmit: function()
         {
         },
         postSubmit: function(data, error)
         {
            if(!error)
               this.emit("formExecuted", data);
         }
      });
   }
);
